package com.algorithm;

public class SwapNodesInPairs {


    public static ListNode swapPairs(ListNode head) {
        ListNode headNode=new ListNode();
        headNode.next=head;
        ListNode current=headNode;
        while(current.next!=null&&current.next.next!=null){
            ListNode n1=current.next;
            ListNode n2=current.next.next;
            current.next=n2;
            n1.next=n2.next;
            n2.next=n1;
            current=n1;
        }
        return headNode.next;
    }

    public static void main(String[] args) {
        ListNode listNode=new ListNode(1,new ListNode(2,new ListNode(3,new ListNode(4,new ListNode(5,new ListNode(6))))));
        ListNode node = swapPairs(listNode);
        System.out.println(node);
    }

}
